<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BasePatientAddresses {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_strAddressLine1;
	protected $m_strAddressLine2;
	protected $m_strArea;
	protected $m_strPinCode;
	protected $m_strStreetDetals;
	protected $m_intAddressType;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_intUpdatedOn;
	protected $m_intT;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getAddressLine1(){
		return $this->m_strAddressLine1;
	}

	public function getAddressLine2(){
		return $this->m_strAddressLine2;
	}

	public function getArea(){
		return $this->m_strArea;
	}

	public function getPinCode(){
		return $this->m_strPinCode;
	}

	public function getStreetDetals(){
		return $this->m_strStreetDetals;
	}

	public function getAddressType(){
		return $this->m_intAddressType;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_intUpdatedOn;
	}

	public function getT(){
		return $this->m_intT;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setAddressLine1( $AddressLine1 ){
		$this->m_strAddressLine1 = $AddressLine1;
	}

	public function setAddressLine2( $AddressLine2 ){
		$this->m_strAddressLine2 = $AddressLine2;
	}

	public function setArea( $Area ){
		$this->m_strArea = $Area;
	}

	public function setPinCode( $PinCode ){
		$this->m_strPinCode = $PinCode;
	}

	public function setStreetDetals( $StreetDetals ){
		$this->m_strStreetDetals = $StreetDetals;
	}

	public function setAddressType( $AddressType ){
		$this->m_intAddressType = $AddressType;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_intUpdatedOn = $UpdatedOn;
	}

	public function setT( $T ){
		$this->m_intT = $T;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into PATIENT_ADDRESSES (patient_id, address_line1, address_line2, area, pin_code, street_detals, address_type, created_by, created_on, updated_by, updated_on, t) values (" . $this->getPatientId() . ", '" . $this->getAddressLine1() . "', '" . $this->getAddressLine2() . "', '" . $this->getArea() . "', '" . $this->getPinCode() . "', '" . $this->getStreetDetals() . "', " . $this->getAddressType() . ", " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL , " . $this->getT() . ")");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE PATIENT_ADDRESSES set  patient_id= " . $this->getPatientId() . ", address_line1= '" . $this->getAddressLine1() . "', address_line2= '" . $this->getAddressLine2() . "', area= '" . $this->getArea() . "', pin_code= '" . $this->getPinCode() . "', street_detals= '" . $this->getStreetDetals() . "', address_type= " . $this->getAddressType() . ", created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now() ,  t= " . $this->getT() . " where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM patient_addresses WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'patient_addresses'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}